#!/usr/bin/env python

import os,sys
import torch
import torch_npu
from torch import distributed as dist

os.environ['RANK'] = "0"
os.environ['WORLD_SIZE'] = "1"
os.environ['MASTER_ADDR'] = "localhost"
os.environ['MASTER_PORT'] = "10099"
dist.init_process_group(backend='hccl', init_method='env://')
rank = dist.get_rank()
tensor = torch.ones(1).npu()
dist.all_reduce(tensor)
print(f"Rank {rank}: AllReduce succeeded.")
